package com.hzjh.h5mall.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.hzjh.base.style.weight.GlideUtils.loadCenterCorp
import com.hzjh.base.utils.function.visibleOrGone
import com.hzjh.h5mall.R
import com.hzjh.h5mall.bean.ads.AdsBannerBean
import com.youth.banner.adapter.BannerAdapter

class AdBannerAdapter(data:List<AdsBannerBean>,
                    val context: Context,
                    val call: (jumpUrl: AdsBannerBean) -> Unit,): BannerAdapter<AdsBannerBean,AdBannerAdapter.BannerViewHolder>(data) {

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val view: View =
            LayoutInflater.from(context).inflate(R.layout.item_image_banner_ad, parent, false)
        return BannerViewHolder(view)
    }

    override fun onBindView(holder: BannerViewHolder?, data: AdsBannerBean, position: Int, size: Int) {
        holder?.ivPlayTag?.visibleOrGone(data.type == 12)
        holder?.img?.let {
            it.loadCenterCorp(data.img)
            it.setOnClickListener {
                call(data)
            }
        }
    }

    class BannerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var img: ImageView
        var ivPlayTag:ImageView
        init {
            img = view.findViewById(R.id.iv_post)
            ivPlayTag=view.findViewById(R.id.iv_play_tag)
        }
    }
}